package cq.zhcqk.activity;

import android.content.Intent;
import android.graphics.Bitmap;
import android.view.KeyEvent;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.dou361.dialogui.DialogUIUtils;

import cq.zhcqk.MainActivity;
import cq.zhcqk.R;
import cq.zhcqk.base.BaseActivity;
import cq.zhcqk.util.Common;
import cq.zhcqk.util.WebViewHeader;
import cq.zhcqk.util.x5.X5WebView;

/**
 * Created by zhangle on 2018/3/4.
 */
public class StartPageActivity extends BaseActivity implements View.OnClickListener{
    private String pageUrl;
    private X5WebView tc_webview;
    @Override
    protected void initView() {
        setContentView(R.layout.activity_start_page);
        pageUrl = getIntent().getStringExtra("pageUrl");
        tc_webview = (X5WebView) findViewById(R.id.tc_webview);
    }

    @Override
    protected void initData() {
        initBack();
        WebViewHeader.setHeaderAndLoadX5(tc_webview, pageUrl);
        show();
    }

    private void initBack(){
        ImageView back = (ImageView) findViewById(R.id.header_back);
        TextView title = (TextView) findViewById(R.id.header_text);
        title.setText("和美磁器口");
        back.setOnClickListener(this);
    }

    public void show(){
        if(tc_webview != null)
        {
            tc_webview.setWebViewClient(new com.tencent.smtt.sdk.WebViewClient()
            {
                @Override
                public void onPageFinished(com.tencent.smtt.sdk.WebView webView, String s) {
                    super.onPageFinished(webView, s);
                    DialogUIUtils.dismiss(buildBean);
                }

                @Override
                public void onPageStarted(com.tencent.smtt.sdk.WebView webView, String s, Bitmap bitmap) {
                    super.onPageStarted(webView, s, bitmap);
                    buildBean.show();
                }
            });
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.header_back:
                startActivity(new Intent(context,MainActivity.class));
                finish();
                break;
        }
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            startActivity(new Intent(context,MainActivity.class));
            finish();
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }
}
